package view;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.TextField;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;

public class Form extends RoundedPanel{
	
	private JTextField urlField, rmiField, portField;
	
	
	public Form(){
		
		setLayout(new GridBagLayout());
		
		urlField = new JTextField("http://www.math.unipd.it/~conti/teaching/PCD1112/project_config.txt",35);
		add(new JLabel("URL:"),new GridBagConstraints(0,0,1,1,1,0,GridBagConstraints.PAGE_START,GridBagConstraints.NONE,new Insets(5,5,10,10),0,0));
		add(urlField, new GridBagConstraints(1,0,1,1,1,1,GridBagConstraints.PAGE_START,GridBagConstraints.HORIZONTAL,new Insets(5,5,0,10),0,0));
		
		portField = new JTextField("", 5);
		portField.setDocument(new IntegerDocument());
		portField.setText("80");
		add(new JLabel("port:"),new GridBagConstraints(2,0,1,1,1,0,GridBagConstraints.PAGE_START,GridBagConstraints.NONE,new Insets(5,5,10,10),0,0));
		add(portField, new GridBagConstraints(3,0,1,1,1,1,GridBagConstraints.PAGE_START,GridBagConstraints.NONE,new Insets(5,5,0,10),0,0));
		
		rmiField = new JTextField("localhost", 50);
		add(new JLabel("RMI:"),new GridBagConstraints(0,1,1,1,1,0,GridBagConstraints.PAGE_START,GridBagConstraints.NONE,new Insets(5,5,10,10),0,0));
		add(rmiField, new GridBagConstraints(1,1,3,1,1,1,GridBagConstraints.PAGE_START,GridBagConstraints.NONE,new Insets(5,5,10,10),0,0));
		
		
	}

	/**
	 * Returns the text that is presented by this text component. By default, this is http://www.math.unipd.it/~conti/teaching/PCD1112/project_config.txt
	 * @return the URL inserted by the user
	 */
	public String getURL(){
		return urlField.getText();
	}
	
	public void editableURL(boolean b){
		urlField.setEditable(b);
		portField.setEditable(b);
	}
	
	public void editableRMI(boolean b){
		rmiField.setEditable(b);
	}
	
	/**
	 * Returns the text that is presented by this text component. By default, this is localhost
	 * @return the RMI inserted by the user
	 */
	public String getRMI(){
		return rmiField.getText();
	}
	
	/**
	 * Returns the text that is presented by this text component. By default, this is 80
	 * @return the port inserted by the user
	 */
	public int getPort(){
		return Integer.parseInt(portField.getText());
	}
	
}
